//
//  YXDownloadManagementViewController.m
//  MockProject
//
//  Created by 周丽丽 on 16/8/23.
//  Copyright © 2016年 niuzhaowang. All rights reserved.
//

#import "YXDownloadManagementViewController.h"
#import "YXDownloadViewController.h"
#import "YXDownloadCompletedViewController.h"
@interface YXDownloadManagementViewController ()
@property (nonatomic, strong) UIView *optionView;
@property (nonatomic, strong) UIButton *downloadButton;
@property (nonatomic, strong) UIButton *downloadCompletedButton;
@property (nonatomic, strong) UIView *verticalLineView;
@property (nonatomic, strong) UIView *horizontalLineView;
@property (nonatomic, strong) UIView *taskListStateView;
@property (nonatomic, strong) UIView *downloadView;
@property (nonatomic, strong) UIView *downloadCompleteView;
@property (nonatomic, strong) UIView *deleteView;
@property (nonatomic, strong) UIView *deleteHorizontalLineView;
@property (nonatomic, strong) UIButton *selectAllButton;
@property (nonatomic, strong) UIView *deleteVerticalLineView;
@property (nonatomic, strong) UIButton *deleteButton;
@property (nonatomic, strong) UISwipeGestureRecognizer *leftDirectionRecognizer;
@property (nonatomic, strong) UISwipeGestureRecognizer *rightDirectionRecognizer;
@end
@implementation YXDownloadManagementViewController
- (void)viewDidLoad {
    [super viewDidLoad];
    self.view.backgroundColor = [UIColor whiteColor];
    self.title = @"下载管理";
    [self setupBackButton];
    [self setupSubviews];
    [self setupSubviewsLayout];
    [self downloadBtnClick:self.downloadButton];
    self.downloadButton.selected = YES;
    [self setupTableView];
    [self setupRecognizer];
}
- (void)setupBackButton{
    
    UIButton *backBtn = [UIButton buttonWithType:UIButtonTypeCustom];
    backBtn.frame = CGRectMake(0, 0, 30, 30);
    [backBtn setImage:[UIImage imageNamed:@"返回按钮正常态"] forState:UIControlStateNormal];
    [backBtn setImage:[UIImage imageNamed:@"返回按钮-点击态"] forState:UIControlStateSelected];
    [backBtn addTarget:self action:@selector(doBack:) forControlEvents:UIControlEventTouchUpInside];
    UIBarButtonItem *backItem = [[UIBarButtonItem alloc] initWithCustomView:backBtn];
    self.navigationItem.leftBarButtonItem = backItem;
}
-(void)doBack:(id)sender{
    [self.navigationController popViewControllerAnimated:YES];
}
- (void)downloadBtnClick:(UIButton *)downloadButton{
    downloadButton.selected = YES;
    self.downloadCompletedButton.selected = NO;
    [self.taskListStateView bringSubviewToFront:self.downloadView];
}
- (void)downloadCompletedBtnClick:(UIButton *)downloadCompletedButton{
    self.downloadButton.selected = NO;
    downloadCompletedButton.selected = YES;
    [self.taskListStateView bringSubviewToFront:self.downloadCompleteView];
}
- (void)setupTableView{
    YXDownloadViewController *downloadVc = [[YXDownloadViewController alloc]init];
    [self addChildViewController:downloadVc];
    [self.taskListStateView addSubview:downloadVc.view];
    self.downloadView = downloadVc.view;
    [self.downloadView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.left.right.bottom.equalTo(self.taskListStateView);
    }];
    YXDownloadCompletedViewController *downloadCompletedVc = [[YXDownloadCompletedViewController alloc]init];
    downloadCompletedVc.view.frame = self.taskListStateView.bounds;
    [self addChildViewController:downloadCompletedVc];
    [self.taskListStateView addSubview:downloadCompletedVc.view];
    self.downloadCompleteView = downloadCompletedVc.view;
    [self.downloadCompleteView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.left.right.bottom.equalTo(self.taskListStateView);
    }];
    [self.taskListStateView bringSubviewToFront:self.downloadView];
}
- (void)setupSubviews{
    UIView *optionV = [[UIView alloc]init];
    [self.view addSubview:optionV];
    self.optionView = optionV;
    
    UIButton *downloadBtn = [UIButton buttonWithType:UIButtonTypeCustom];
    downloadBtn.titleLabel.font = [UIFont systemFontOfSize:13];
    [downloadBtn setTitle:@"下载中..." forState:UIControlStateNormal];
    [downloadBtn setTitle:@"下载中..." forState:UIControlStateSelected];
    [downloadBtn setTitleColor:[UIColor colorWithHexString:@"403e3d"] forState:UIControlStateNormal];
    [downloadBtn setTitleColor:[UIColor colorWithHexString:@"ff4600"] forState:UIControlStateSelected];
    [downloadBtn setImage:[UIImage imageNamed:@"下载中图标正常态"] forState:UIControlStateNormal];
    [downloadBtn setImage:[UIImage imageNamed:@"下载中图标当前选择态"] forState:UIControlStateSelected];
    [downloadBtn addTarget:self action:@selector(downloadBtnClick:) forControlEvents:UIControlEventTouchUpInside];
    [self.optionView addSubview:downloadBtn];
    self.downloadButton = downloadBtn;
    
    UIView *verticalLineV = [[UIView alloc]init];
    verticalLineV.backgroundColor = [UIColor colorWithHexString:@"e2e2e4"];
    [self.optionView addSubview:verticalLineV];
    self.verticalLineView = verticalLineV;
    
    UIView *horizontalLineV = [[UIView alloc]init];
    horizontalLineV.backgroundColor = [UIColor blackColor];
    horizontalLineV.alpha = 0.2;
    [self.optionView addSubview:horizontalLineV];
    self.horizontalLineView = horizontalLineV;
    
    UIButton *downloadCompletedBtn = [UIButton buttonWithType:UIButtonTypeCustom];
    downloadCompletedBtn.titleLabel.font = [UIFont systemFontOfSize:13];
    [downloadCompletedBtn setTitle:@"下载完成" forState:UIControlStateNormal];
    [downloadCompletedBtn setTitle:@"下载完成" forState:UIControlStateSelected];
    [downloadCompletedBtn setTitleColor:[UIColor colorWithHexString:@"403e3d"] forState:UIControlStateNormal];
    [downloadCompletedBtn setTitleColor:[UIColor colorWithHexString:@"ff4600"] forState:UIControlStateSelected];
    [downloadCompletedBtn setImage:[UIImage imageNamed:@"下载完成图表正常态"] forState:UIControlStateNormal];
    [downloadCompletedBtn setImage:[UIImage imageNamed:@"下载完成图表当前选择态"] forState:UIControlStateSelected];
    [downloadCompletedBtn addTarget:self action:@selector(downloadCompletedBtnClick:) forControlEvents:UIControlEventTouchUpInside];
    [self.optionView addSubview:downloadCompletedBtn];
    self.downloadCompletedButton = downloadCompletedBtn;
    
    UIView *taskListStateV = [[UIView alloc]init];
    [self.view addSubview:taskListStateV];
    self.taskListStateView = taskListStateV;
    
}
- (void)setupSubviewsLayout{
    [self.optionView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.view).offset(64);
        make.left.right.equalTo(self.view);
        make.height.mas_equalTo(44);
    }];
    [self.downloadButton mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.optionView);
        make.left.equalTo(self.optionView);
        make.width.mas_equalTo(self.view.width * 0.5);
        make.height.equalTo(self.optionView);
    }];
    [self.verticalLineView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerY.equalTo(self.optionView);
        make.left.equalTo(self.downloadButton.mas_right);
        make.width.mas_equalTo(1);
        make.height.mas_equalTo(20);
    }];
    [self.downloadCompletedButton mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.verticalLineView);
        make.left.equalTo(self.verticalLineView.mas_right);
        make.right.equalTo(self.optionView);
        make.height.equalTo(self.verticalLineView);
    }];
    [self.horizontalLineView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.bottom.equalTo(self.optionView);
        make.left.right.equalTo(self.optionView);
        make.height.mas_equalTo(1);
    }];
    [self.taskListStateView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.optionView.mas_bottom);
        make.bottom.left.right.equalTo(self.view);
    }];
}
- (void)setupRecognizer{
    UISwipeGestureRecognizer *leftRecognizer = [[UISwipeGestureRecognizer alloc]initWithTarget:self action:@selector(leftHandleSwipeFrom)];
    leftRecognizer.direction = UISwipeGestureRecognizerDirectionRight;
    [self.view addGestureRecognizer:leftRecognizer];
    self.leftDirectionRecognizer = leftRecognizer;
    UISwipeGestureRecognizer *rightRecognizer = [[UISwipeGestureRecognizer alloc]initWithTarget:self action:@selector(rightHandleSwipeFrom)];
    rightRecognizer.direction = UISwipeGestureRecognizerDirectionLeft;
    [self.view addGestureRecognizer:rightRecognizer];
    self.rightDirectionRecognizer = rightRecognizer;
}
- (void)leftHandleSwipeFrom{
    [self downloadBtnClick:self.downloadButton];
}
- (void)rightHandleSwipeFrom{
    [self downloadCompletedBtnClick:self.downloadCompletedButton];
}
- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

@end
